package com.yonyou.cyxdms.basedata.service.service.option.impl;

    
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoleilu.hutool.util.StrUtil;
import com.yonyou.cms.channel.client.vo.message.DealerAttachVO;
import com.yonyou.cyx.function.utils.jsonserializer.JSONUtil;
import com.yonyou.cyxdms.basedata.client.constants.BaseDataCommonConstants;
import com.yonyou.cyxdms.basedata.client.domains.vo.MQBaseVO;
import com.yonyou.cyxdms.basedata.client.domains.vo.PackageCacheVO;
import com.yonyou.cyxdms.basedata.client.domains.vo.VsOptionVO;
import com.yonyou.cyxdms.basedata.client.service.basedata.BaseCommonSeriesService;
import com.yonyou.cyxdms.basedata.service.entity.brand.BrandPO;
import com.yonyou.cyxdms.basedata.service.entity.configurer.PackagePO;
import com.yonyou.cyxdms.basedata.service.entity.option.VsOptionPO;
import com.yonyou.cyxdms.basedata.service.repository.basedata.SystemParamMapper;
import com.yonyou.cyxdms.basedata.service.repository.option.VsOptionMapper;
import com.yonyou.cyxdms.basedata.service.service.brand.BrandService;
import com.yonyou.cyxdms.basedata.service.service.option.VsOptionService;
import com.yonyou.cyxdms.basedata.service.util.EasyPoiUtil;
import com.yonyou.cyxdms.basedata.service.util.MQUtils;
import com.yonyou.cyxdms.basedata.service.util.MapUtils;
import com.yonyou.cyxdms.basedata.service.vo.option.VehicleProductOptionVO;
import com.yonyou.cyxdms.basedata.service.vo.packages.PackageDictVO;
import com.yonyou.cyxdms.basedata.service.vo.packages.VehicleProductPackageVO;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonyou.cyxdms.basedata.service.constant.BasedataCommonConstants;
import com.yonyou.cyxdms.basedata.service.constant.BasedataDictConstants;
import com.yonyou.cyxdms.basedata.service.dto.option.VsOptionDTO;
import com.yonyou.cyxdms.basedata.service.dto.vehiclemodel.OptionModifyDTO;
import com.yonyou.cyxdms.basedata.service.dto.vehiclemodel.OptionQueryDTO;
import com.yonyou.cyxdms.basedata.service.dto.vehiclemodel.PackageModifyDTO;
import com.yonyou.cyxdms.basedata.service.dto.vehiclemodel.PackageQueryDTO;
import com.yonyou.cloud.http.plus.remote.IRemoteInvoke;
import com.yonyou.cyx.framework.compent.redis.RedisClient;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyx.function.exception.DALException;
import com.yonyou.cyx.function.exception.ServiceBizException;
import com.yonyou.cyx.function.utils.bean.BeanMapperUtil;
import com.yonyou.cyx.function.utils.common.CommonUtils;
import com.yonyou.cyx.function.utils.common.StringUtils;
import com.yonyou.cyxdms.sysmanage.client.service.login.DealerBrandService;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;


/**
 * <p>
 *  选装服务实现类
 * </p>
 *
 * @author zys
 * @since 2020-02-10
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class VsOptionServiceImpl extends ServiceImpl<VsOptionMapper, VsOptionPO> implements VsOptionService {
    //日志对象
    private static final Logger logger = LoggerFactory.getLogger(VsOptionServiceImpl.class);
    @Autowired
    VsOptionMapper vsOptionMapper;

    @Autowired
    DealerBrandService dealerBrandService;
    
    @Autowired
    private RedisClient redisClient;
    
    @Autowired
    SystemParamMapper systemParamMapper;
    
    @Autowired
    IRemoteInvoke iRemoteInvoke;
    
    @Autowired
    private BrandService brandService;

    /**
     * 分页查询对应数据
     *
     * @param page 分页对象
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage<java.util.Map<java.lang.String,java.lang.Object>>
     * @author zys
     * @since 2018/7/22 0022
     */
    @Override
    @SuppressWarnings("unchecked")
    @Transactional(readOnly = true)
    public IPage<Map<String, Object>> selectPageBysql(Page page, Map<String, Object> queryCondition) {
        // 获取总条数
        page.setRecords(vsOptionMapper.selectPageBySql(page, queryCondition));
        return page;
    }

    /**
     * 根据查询条件返回结果集
     *
     * @param queryCondition 查询条件
     * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     * @author zys
     * @since 2018/7/22 0022
     */
    @Override
    @Transactional(readOnly = true)
    public List<Map<String,Object >> selectListBySql(Map<String, Object> queryCondition) {
        return vsOptionMapper.selectListBySql(queryCondition);
    }

    /**
     * 根据查询条件返回结果集
     *
     * @param id 主键ID
     * @return java.util.List<java.util.Map < java.lang.String , java.lang.Object>>
     * @author zys
     * @since 2018/7/22 0022
     */
    @Override
    @Transactional(readOnly = true)
    public Map<String, Object> getById(Long id) {
        VsOptionPO vsOptionPo = vsOptionMapper.selectById(id);
        if(vsOptionPo!=null){
            return vsOptionPo.toMaps();
        }else{
            throw new DALException("查询失败,没有符合条件的数据");
        }
    }

    /**
     * 根据DTO 进行数据新增
     *
     * @param vsOptionDTO 页面DTO
     * @return void
     * @author zhangxianchao
     * @since 2018/7/21 0021
     */
    @Override
    public Map<String,Object> insert(VsOptionDTO vsOptionDTO) {
        //对对象进行赋值操作
        VsOptionPO vsOptionPo = vsOptionDTO.transDtoToPo(VsOptionPO.class);
        //执行插入
        vsOptionMapper.insert(vsOptionPo);
        //返回插入的值
        return vsOptionMapper.selectById(vsOptionPo.getOptionId()).toMaps();
    }

    /**
     * 根据DTO 及ID 进行数据更新
     *
     * @param id 主键ID
     * @param vsOptionDTO 页面DTO
     * @return void
     * @author zhangxianchao
     * @since 2018/7/21 0021
     */
    @Override
    public Map<String,Object> update(Long id, VsOptionDTO vsOptionDTO) {
        VsOptionPO vsOptionPo = vsOptionMapper.selectById(id);
        //对对象进行赋值操作
        vsOptionDTO.transDtoToPo(vsOptionPo);
        //执行更新
        vsOptionMapper.updateById(vsOptionPo);
        return vsOptionPo.toMaps();
    }

    /**
     * 根据ID 进行删除数据
     *
     * @param id
     * @return void
     * @author zhangxianchao
     * @since 2018/8/25 0025
     */
    @Override
    public void deleteById(Long id) {
        int deleteCount = vsOptionMapper.deleteById(id);
        logger.debug("删除数量：{}",deleteCount);
        if (deleteCount<=0) {
            throw new DALException("删除失败,没有符合条件的数据");
        }
    }

    /**
     * 根据ids 进行删除
     *
     * @param ids
     * @return void
     * @author zhangxianchao
     * @since 2018/8/25 0025
     */
    @Override
    public void deleteBatchIds(String ids) {
        List<Long> longList = StringUtils.convertStrToArray(ids,",", Long.class);
        int deleteCount = vsOptionMapper.deleteBatchIds(longList);
        logger.debug("删除数量：{}",deleteCount);
        if (deleteCount!=longList.size()) {
            throw new DALException("删除失败,没有符合条件的数据");
        }
    }

	@Override
	public List<Map<String, Object>> getOptionByPackageId(Long packageId) {
		LoginInfoDto loginInfo = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        return vsOptionMapper.getOptionByPackageId(packageId, loginInfo.getAppId());
	}

    @Override
    public List<VsOptionVO> queryOptionByCondition(Map<String, Object> queryParam) {
        List<Long> brandIdList = dealerBrandService.queryBrandIdList();
        if(brandIdList.size()>0){
            queryParam.put("brandIdList", brandIdList);
        }
        if(!ObjectUtils.isEmpty(queryParam.get("recordTime"))){
            String recordTimeSt = (String) queryParam.get("recordTime");
            Long recordTimeL = Long.valueOf(recordTimeSt);
            LocalDateTime recordTime = ofEpochSecond(recordTimeL);
            String format  = "yyyy-MM-dd HH:mm:ss";
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);
            String recordTimeS = recordTime.format(dateTimeFormatter);
            queryParam.put("recordTime",recordTimeS);
        }
        return vsOptionMapper.queryOptionByCondition(queryParam);
    }

    /**
     * 秒级时间戳转 LocalDateTime
     * @param epochSecond 秒级时间戳
     * @return LocalDateTime
     */
    private static LocalDateTime ofEpochSecond(long epochSecond){
        return LocalDateTime.ofEpochSecond(epochSecond, 0, ZoneOffset.of("+8"));
    }

    /**
     * Dcs根据查询条件返回对应的选装数据
     *
     * @param page
     * @param queryParam
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.yonyou.cyxdms.basedata.service.vo.option.VehicleProductOptionVO>
     * @author zhangys
     * @since 2020/2/24
     */
    @Override
    public IPage<VehicleProductOptionVO> queryVehicleProductDcsOption(Page page, Map<String, Object> queryParam) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        MapUtils.addParameter(queryParam, loginInfoDto.getOwnerCode(), loginInfoDto.getAppId(), loginInfoDto.getGroupCode());
        List<VehicleProductOptionVO> vehicleProductOptionVos = vsOptionMapper.queryVehicleProductDcsOption(page, queryParam);
        page.setRecords(vehicleProductOptionVos);
        return page;
    }
    
    /**
     * dcs新增选装
     *
     * @param optionModifyDTO
     * @return java.lang.Integer
     * @author zhangys
     * @since 2020/2/24
     */
    @Override
    public Integer addDcsOption(OptionModifyDTO optionModifyDTO) {
        String appId = BasedataCommonConstants.APP_ID_RL;
        String groupCode = "-1";
        LambdaQueryWrapper<VsOptionPO> queryWrapper = new LambdaQueryWrapper<VsOptionPO>();
        queryWrapper.eq(VsOptionPO::getPackageId, optionModifyDTO.getOptionId());
        queryWrapper.eq(VsOptionPO::getOptionCode, optionModifyDTO.getOptionCode());
        // 判断同一家店面中是否存在相同的配置代码或名称
        List<VsOptionPO> optionPos = vsOptionMapper.selectList(queryWrapper);
        if (!CommonUtils.isNullOrEmpty(optionPos)) {
            return 0;
        }
        VsOptionPO vsOptionPo = BeanMapperUtil.copyProperties(optionModifyDTO, VsOptionPO.class);
        vsOptionPo.setDataSources(BasedataDictConstants.DATA_SOURCES_BY_SUPER);
        vsOptionPo.setAppId(BasedataCommonConstants.APP_ID_RL);
        vsOptionPo.setCompanyCode("-1");
        vsOptionPo.setOwnerCode("-1");
        vsOptionPo.setOwnerParCode("-1");
        vsOptionPo.setIsIssue(BasedataDictConstants.IS_NO_SEND);
        int insertSize = vsOptionMapper.insert(vsOptionPo);
        // 发送数据到MQ
//        sendPackage(vsOptionPo, BasedataCommonConstants.BIZ_OPTION_INSERT);
        // 删除redis缓存
        String messageFormat = MessageFormat.format(BaseDataCommonConstants.PACKAGE_CACHE_OPTION_ALL, appId, groupCode);
        redisClient.del(messageFormat);
        String productFormat = MessageFormat.format(BaseDataCommonConstants.PRODUCT_CACHE_DATA, appId, BasedataCommonConstants.PRODUCT_REDIS_TYPE, BasedataCommonConstants.PRODUCT_REDIS_LEVEL);
        redisClient.del(productFormat);
        return insertSize;
    }
    
    /**
     * dcs修改选装
     *
     * @param id
     * @param optionModifyDTO
     * @return java.lang.Integer
     * @author zhangys
     * @since 2020/2/24
     */
    @Override
    public Integer modifyDcsOption(Long id, OptionModifyDTO optionModifyDTO) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        VsOptionPO optionPo = vsOptionMapper.selectById(id);
        if (optionPo != null) {
            optionPo.setPackageId(optionModifyDTO.getPackageId());
            optionPo.setOptionCode(optionModifyDTO.getOptionCode());
            optionPo.setOptionName(optionModifyDTO.getOptionName());
            optionPo.setDataSources(optionModifyDTO.getDataSources());
            optionPo.setIsValid(optionModifyDTO.getIsValid());
            optionPo.setRecordVersion(optionModifyDTO.getRecordVersion());
            optionPo.setIsIssue(BasedataDictConstants.IS_NO_SEND);
            int updateSize = vsOptionMapper.updateById(optionPo);
            if (updateSize == 0) {
                throw new ServiceBizException(BasedataCommonConstants.UPDATE_FAILED);
            }

            // 删除redis缓存
            String messageFormat = MessageFormat.format(BaseDataCommonConstants.PACKAGE_CACHE_OPTION_ALL, loginInfoDto.getAppId(), loginInfoDto.getGroupCode());
            redisClient.del(messageFormat);
            String productFormat = MessageFormat.format(BaseDataCommonConstants.PRODUCT_CACHE_DATA, loginInfoDto.getAppId(), BasedataCommonConstants.PRODUCT_REDIS_TYPE, BasedataCommonConstants.PRODUCT_REDIS_LEVEL);
            redisClient.del(productFormat);
            // 发送数据到MQ
            sendPackage(optionPo, BasedataCommonConstants.BIZ_OPTION_UPDATE);
            return updateSize;
        } else {
            throw new ServiceBizException("后台不存在该配置！");
        }
    }
    
    /**
     * 查询选装信息（pc）
     *
     * @param page
     * @param optionQueryDTO
     * @author zhangys
     * @since 2020/2/24
     */
    @Override
    public IPage<VehicleProductOptionVO> queryVehicleProductOption(Page page, OptionQueryDTO optionQueryDTO) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);

        if (StrUtil.isNotEmpty(optionQueryDTO.getVehicleInfo())) {
            List<String> list = Arrays.asList(optionQueryDTO.getVehicleInfo().split(","));
            int listSize = list.size();
            if (listSize >= 1) {
                //品牌
                optionQueryDTO.setBrandId(Long.valueOf(list.get(0)));
            }
            if (listSize >= 2) {
                //车系
                optionQueryDTO.setSeriesId(Long.valueOf(list.get(1)));
            }
            if (listSize >= 3) {
                //车型
                optionQueryDTO.setModelId(Long.valueOf(list.get(2)));
            }
            if (listSize >= 4) {
                //配置
                optionQueryDTO.setPackageId(Long.valueOf(list.get(3)));
            }
            if (listSize >= 5) {
                //选装
                optionQueryDTO.setOptionId(Long.valueOf(list.get(4)));
            }

        }

        Map<String, Object> queryParam = optionQueryDTO.toMaps();
        queryParam = brandService.setLoginInfoParam(queryParam, loginInfoDto);
            logger.info("查询配置IPage的queryParam:------------------{}", queryParam);
        /**
         * 选装数据放置redis
         */
        String appId = loginInfoDto.getAppId();
        String messageFormat = MessageFormat.format(BasedataCommonConstants.OPTION_CACHE_PRODUCT_OPTIONID, appId);
        Object vsOptionData = redisClient.get(messageFormat);
        if (null == vsOptionData) {
            LambdaQueryWrapper<VsOptionPO> vsOptionParam = new QueryWrapper<VsOptionPO>().lambda();
            vsOptionParam.eq(VsOptionPO::getAppId, appId).orderByAsc(VsOptionPO::getOptionCode,VsOptionPO::getOptionName);
            List<VsOptionPO> vsOptionList = vsOptionMapper.selectList(vsOptionParam);
            List<VsOptionVO> vsOptionVOList = BeanMapperUtil.copyList(vsOptionList, VsOptionVO.class);
            redisClient.set(messageFormat, JSONUtil.objectToJson(vsOptionVOList), BaseDataCommonConstants.EXPIRE_TIME_ONE_DAY);
        }
        page.setRecords(vsOptionMapper.queryVehicleProductOption(page, queryParam));
        return page;
    }

    /**
     * 新增选装
     *
     * @param optionModifyDTO
     * @return java.lang.Integer
     * @author zhangys
     * @since 2020/2/25
     */
    @Override
    public Integer addOption(OptionModifyDTO optionModifyDTO) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        QueryWrapper<VsOptionPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(VsOptionPO::getAppId, loginInfoDto.getAppId())
                .in(VsOptionPO::getOwnerCode, loginInfoDto.getOwnerCode())
                .and(obj ->
                        obj.eq(VsOptionPO::getOptionCode, optionModifyDTO.getOptionCode())
                                .or()
                                .eq(VsOptionPO::getOptionName, optionModifyDTO.getOptionName()));
        // 判断同一家店面中是否存在相同的配置代码或名称
        List<VsOptionPO> optionPos = vsOptionMapper.selectList(queryWrapper);
        if (!CommonUtils.isNullOrEmpty(optionPos)) {
            throw new ServiceBizException(BasedataCommonConstants.OPTION_NOT_REPEAT);
        }
        VsOptionPO optionPo = BeanMapperUtil.copyProperties(optionModifyDTO, VsOptionPO.class);
        int insertSize = vsOptionMapper.insert(optionPo);
        // 发送数据到MQ
        sendPackage(optionPo, BasedataCommonConstants.BIZ_OPTION_INSERT);
        // 删除redis缓存
        String messageFormat = MessageFormat.format(BaseDataCommonConstants.PACKAGE_CACHE_OPTION_ALL, loginInfoDto.getAppId(), loginInfoDto.getOwnerCode());
        redisClient.del(messageFormat);

        return insertSize;
    }
    
    /**
     * 修改选装
     *
     * @param id
     * @param optionModifyDTO
     * @return java.lang.Integer
     * @author zhangys
     * @since 2020/2/25
     */
    @Override
    public Integer modifyOption(Long id, OptionModifyDTO optionModifyDTO) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        VsOptionPO optionPo = vsOptionMapper.selectById(id);
        if (optionPo != null) {
            QueryWrapper<VsOptionPO> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda()
                    .in(VsOptionPO::getOwnerCode, loginInfoDto.getOwnerCode())
                    .eq(VsOptionPO::getAppId, loginInfoDto.getAppId())
                    .notIn(VsOptionPO::getOptionId, id)
                    .and(obj ->
                            obj.eq(VsOptionPO::getOptionCode, optionModifyDTO.getOptionCode())
                                    .or()
                                    .eq(VsOptionPO::getOptionName, optionModifyDTO.getOptionName()));
            // 判断同一家店面中是否存在相同的配置代码或名称
            List<VsOptionPO> optionPos = vsOptionMapper.selectList(queryWrapper);
            if (!CommonUtils.isNullOrEmpty(optionPos)) {
                throw new ServiceBizException(BasedataCommonConstants.OPTION_NOT_REPEAT);
            } else {
                optionPo.setPackageId(optionModifyDTO.getPackageId());
                optionPo.setOptionCode(optionModifyDTO.getOptionCode());
                optionPo.setOptionName(optionModifyDTO.getOptionName());
                optionPo.setIsValid(optionModifyDTO.getIsValid());
                optionPo.setDataSources(optionModifyDTO.getDataSources());
                optionPo.setRecordVersion(optionModifyDTO.getRecordVersion());
                optionPo.setStartDate(optionModifyDTO.getStartDate());
                int updateSize = vsOptionMapper.updateById(optionPo);
                if (updateSize == 0) {
                    throw new ServiceBizException(BasedataCommonConstants.UPDATE_FAILED);
                }
                // 删除redis缓存
                String messageFormat = MessageFormat.format(BaseDataCommonConstants.PACKAGE_CACHE_OPTION_ALL, loginInfoDto.getAppId(), loginInfoDto.getOwnerCode());
                redisClient.del(messageFormat);
                // 发送数据到MQ
                sendPackage(optionPo, BasedataCommonConstants.BIZ_OPTION_UPDATE);
                return updateSize;
            }
        } else {
            throw new ServiceBizException("后台不存在该配置！");
        }

    }

	@Override
	public List<VsOptionDTO> getAllOptionByAppId(String appId) {
		LambdaQueryWrapper<VsOptionPO> query = new QueryWrapper<VsOptionPO>().lambda().eq(VsOptionPO::getAppId, appId);
		List<VsOptionPO> optionPoList = this.vsOptionMapper.selectList(query);
		return BeanMapperUtil.copyList(optionPoList, VsOptionDTO.class);
	}


	/**
     * 配置数据发送到MQ
     *
     * @param optionPo
     * @author zhangys
     * @date 2020/2/24
     */
    public void sendPackage(VsOptionPO optionPo, String bizId) {
        List<VsOptionPO> optionList = new ArrayList<>();
        optionList.add(optionPo);
        MQBaseVO<List<VsOptionPO>> optionMq = new MQBaseVO<>(optionList, optionPo.getAppId(), optionPo.getOwnerCode());
        MQUtils.sendMsg(optionMq.toMap(), bizId, systemParamMapper, iRemoteInvoke);
    }

    /**
     * 根据查询条件返回选装
     *
     * @param optionQueryDTO
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.option.VehicleProductOptionVO>
     * @author caozx
     * @since 2020/12/8
     */
    @Override
    public List<VehicleProductOptionVO> queryVehicleProductOption(OptionQueryDTO optionQueryDTO) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        Map<String, Object> queryParam = optionQueryDTO.toMaps();
        queryParam = brandService.setLoginInfoParam(queryParam, loginInfoDto);
        logger.info("查询配置IPage的queryParam:------------------{}", queryParam);
        return vsOptionMapper.queryVehicleProductOption(queryParam);
    }

    /**
     * 品系型查询界面配置选装下拉框
     *
     * @param brandsId, seriesId, modelsId, packageId
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.packages.VehicleProductPackageVO>
     * @author caozx
     * @since 2020/12/14
     */
    @Override
    public List<VehicleProductOptionVO> queryOptipnDictAll(String brandsId, String seriesId, String modelsId, String packageId){
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("seriesId", seriesId);
        queryParam.put("brandsId", brandsId);
        queryParam.put("modelsId", modelsId);
        queryParam.put("packageId", packageId);
        return vsOptionMapper.queryOptipnDictAll(queryParam);
    }

    @Override
    public List<VehicleProductOptionVO> queryVehicleProductOptionNewQuery(OptionQueryDTO optionQueryDTO) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        Map<String, Object> queryParam = optionQueryDTO.toMaps();
       // queryParam = brandService.setLoginInfoParam(queryParam, loginInfoDto);
        queryParam.put(BasedataCommonConstants.APP_ID, loginInfoDto.getAppId());
        logger.info("查询配置IPage的queryParam:------------------{}", queryParam);
        return vsOptionMapper.queryVehicleProductOptionNewQuery(queryParam);
    }

    @Override
    public void downloadUseModelExcel(HttpServletResponse response) throws IOException {
        List<VehicleProductOptionVO> dataList = new ArrayList<>();
        EasyPoiUtil.exportExcelResponse("适用车型导入模板", null, dataList, VehicleProductOptionVO.class, "适用车型导入模板.xls", response);
    }

    @Override
    public Map<String, List> getOptionInfoByExcel(List<VehicleProductOptionVO> dealerList) {
        Map<String,List>  resMap = new HashMap();
        List<VehicleProductOptionVO> optionInfoByExcel = new ArrayList<>();
        List<String> errorList = new ArrayList<>();
        if (dealerList!=null&&dealerList.size()>0){
            List<String> list = dealerList.stream().map(VehicleProductOptionVO::getOptionCode).collect(Collectors.toList());
            Iterator<String> iterator = list.iterator();
            while (iterator.hasNext()){
                String next = iterator.next();
                if (next==null|| "".equals(next.trim())){
                    iterator.remove();
                }
            }
            LoginInfoDto loginInfo = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
            optionInfoByExcel = vsOptionMapper.getOptionInfoByExcel(list, loginInfo.getAppId());
            if (optionInfoByExcel!=null&&optionInfoByExcel.size()>0){
                List<String> resList = optionInfoByExcel.stream().map(VehicleProductOptionVO::getOptionCode).collect(Collectors.toList());
                for (String code : list) {
                    if (!resList.contains(code)){
                        errorList.add(code);
                    }
                }
            }else {
                errorList.addAll(list);
            }
        }
        resMap.put("errorList",errorList);
        resMap.put("successList",optionInfoByExcel);
        return resMap;
    }

    @Override
    public List<VehicleProductOptionVO> queryVehicleProductOptionNoPage(OptionQueryDTO optionQueryDTO) {
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);

        if (StrUtil.isNotEmpty(optionQueryDTO.getVehicleInfo())) {
            List<String> list = Arrays.asList(optionQueryDTO.getVehicleInfo().split(","));
            int listSize = list.size();
            if (listSize >= 1) {
                //品牌
                optionQueryDTO.setBrandId(Long.valueOf(list.get(0)));
            }
            if (listSize >= 2) {
                //车系
                optionQueryDTO.setSeriesId(Long.valueOf(list.get(1)));
            }
            if (listSize >= 3) {
                //车型
                optionQueryDTO.setModelId(Long.valueOf(list.get(2)));
            }
            if (listSize >= 4) {
                //配置
                optionQueryDTO.setPackageId(Long.valueOf(list.get(3)));
            }
            if (listSize >= 5) {
                //选装
                optionQueryDTO.setOptionId(Long.valueOf(list.get(4)));
            }

        }

        Map<String, Object> queryParam = optionQueryDTO.toMaps();
        queryParam = brandService.setLoginInfoParam(queryParam, loginInfoDto);
        logger.info("查询配置IPage的queryParam:------------------{}", queryParam);
        /**
         * 选装数据放置redis
         */
        String appId = loginInfoDto.getAppId();
        String messageFormat = MessageFormat.format(BasedataCommonConstants.OPTION_CACHE_PRODUCT_OPTIONID, appId);
        Object vsOptionData = redisClient.get(messageFormat);
        if (null == vsOptionData) {
            LambdaQueryWrapper<VsOptionPO> vsOptionParam = new QueryWrapper<VsOptionPO>().lambda();
            vsOptionParam.eq(VsOptionPO::getAppId, appId).orderByAsc(VsOptionPO::getOptionCode,VsOptionPO::getOptionName);
            List<VsOptionPO> vsOptionList = vsOptionMapper.selectList(vsOptionParam);
            List<VsOptionVO> vsOptionVOList = BeanMapperUtil.copyList(vsOptionList, VsOptionVO.class);
            redisClient.set(messageFormat, JSONUtil.objectToJson(vsOptionVOList), BaseDataCommonConstants.EXPIRE_TIME_ONE_DAY);
        }
        queryParam.put("isValid",10041001);
        return vsOptionMapper.queryVehicleProductOption(null, queryParam);
    }

    @Override
    public List<VsOptionVO> queryAllOption() {
        return vsOptionMapper.queryAllOption();
    }

    @Override
    public List<PackageDictVO> queryAllPackage() {
        return vsOptionMapper.queryAllPackage();
    }
}
